﻿<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="<%=request.getContextPath()%>/">
    <title>元宇宙商品信息列表</title>
    <script src="js/jquery-3.6.0.js"></script>
    
</head>
<body>
    <div style="width: 700px;margin: auto">
        <h2 style="width: 350px;margin: auto">元宇商品信息列表</h2>
        <table border="1px">
            <tr>
                <th>编号</th>
                <th>名称</th>
                <th>描述</th>
                <th>价格</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${requestScope.list}" var="cs">
                <tr id="${cs.id}">
                    <td>${cs.id}</td>
                    <td>${cs.productName}</td>
                    <td>${cs.productDesc}</td>
                    <td>${cs.productPrice}</td>
                    <td>
                        <c:if test="${cs.flag==1}">
                            上架
                        </c:if>
                        <c:if test="${cs.flag==0}">
                            下架
                        </c:if>
                    </td>
                    <td>
                        <a href="#"  onclick="MerUpdate(${cs.flag},${cs.id})">修改</a>&nbsp;<a onclick="del(${cs.id})" >删除</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <div style="width: 250px;margin: auto"><a href="aaa.jsp">新增信息</a></div>
    </div>
    <script>
        $(function (){8
            $("table tr").css("background-color","pink");
        })
        function  MerUpdate(flag,id) {
            if (confirm("确认修改商品状态么?")) {
                $.ajax({
                    url: "productUpdate",
                    type: "get",
                    dataType: "text",
                    data:{
                        id:id,flag:flag
                    },
                    success: function (data) {
                        if (data == "true") {
                            alert("修改成功!");
                            location.href='mertaver'
                        } else {
                            alert("修改失败!");
                        }
                    }
                })
            }
        }
        function del(id){
            var i=confirm("确认要删除吗?");
            if (i===true) {
                $.ajax({
                    url: "productDelete",
                    type: "get",
                    data: "id=" + id,
                    dataType: "text",
                    success: function (data) {
                        if (data == "true") {
                            alert("删除成功!");
                            $("table #"+id).remove();
                        } else {
                            alert("删除失败!");
                        }
                    }
                })
            }
        }
    </script>
</body>
</html>
